package com.nightcat.dogvscat;

import android.content.Context;
import android.media.AudioManager;
import android.media.SoundPool;

public class Util {
	//声音播放器。
	private static SoundPool mSoundPool;

	private static SoundPool getSoundPool(){
		if(mSoundPool == null){
			return mSoundPool = new SoundPool(4,AudioManager.STREAM_MUSIC,0);
		}else{
			return mSoundPool;
		}
	}
	
    //播放音乐。
    public static void playMusic(int soundId,Context context){
    	AudioManager mgr = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);  
	    int streamVolume = mgr.getStreamVolume(AudioManager.STREAM_MUSIC);  
	    getSoundPool().play(soundId, streamVolume, streamVolume, 1, 0, 0.5f);
    }
    
    //加载音乐。
    public static int loadMusic(int res_id,Context context){
    	int soundID = getSoundPool().load(context, res_id, 5);
    	return soundID;
    }
}
